package net.pm.core.dateEdtor;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.util.regex.Pattern;

import net.pm.common.toolkit.PMTool;
import net.pm.common.toolkit.RegexValidUtils;
import net.pm.common.toolkit.StringUtils;
import net.pm.common.toolkit.date.DateUtils;

import org.springframework.stereotype.Component;

/**Date 自定义数据绑定
 */

@Component("DateEditor_Long")
public class DateEditor_Long extends PropertyEditorSupport {
	

	@Override
	public String getAsText() {
		return PMTool.isEmpty(getValue()) ? "" : getValue().toString();
	}

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		if(StringUtils.isEmpty(text)){
			this.setValue(null);
			return;
		}
		if(!RegexValidUtils.isDateLong(text)){
			return;
		}
		
		try {
			this.setValue(DateUtils.longDateFormat.parse(text));
		} catch (ParseException e) {
			this.setValue(null);
		}
	}
	
	public static void main(String[] args) {
		String text1 = "2012-01-09 13:11:11";
		//String text2 = "2012-01-09";
		
		
		Pattern pattern = Pattern.compile("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$");
		System.out.println(pattern.matcher(text1).find());
	}

}
